﻿using System;
using System.Collections.Generic;
using System.Device.Location;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using RadarControl.Core.GeoItems;
using RadarControl.Helpers;
using RadarTestAppControl.Resources;
using RadarControl.Core;

namespace RadarTestAppControl
{
    public partial class MainPage : PhoneApplicationPage
    {
        List<GeoCoordinate> coordinates = new List<GeoCoordinate>(); 
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            InitalizeSamplePoints();

            radar.PointsReuqested += radar_PointsReuqested;
            
        }

        IEnumerable<RadarControl.Abstracts.IRadarPoint> radar_PointsReuqested(PointsRequestedEventArgs arg)
        {
            List<RadarTemplatedItem> items = new List<RadarTemplatedItem>();

            foreach (var geoItem in coordinates)
            {
                var pItem = new RadarTemplatedItem();
                pItem.Azimuth = (int)LocationHelper.CacheAzimuth(arg.CurrentLocation, geoItem);
                pItem.Distance = (int)LocationHelper.CalculateDistance(arg.CurrentLocation, geoItem);

                if(pItem.Distance <= arg.DesiredPointDistance)
                    items.Add(pItem);
            }

            return items;
        }

        void InitalizeSamplePoints()
        {
            coordinates.Add(new GeoCoordinate(52.387254, 16.972853)); //klatka od smieci
            coordinates.Add(new GeoCoordinate(52.387128, 16.973017));
            coordinates.Add(new GeoCoordinate(52.387461, 16.973347)); //koniec bloku
            coordinates.Add(new GeoCoordinate(52.387154, 16.973896)); // kolo skrótu
            coordinates.Add(new GeoCoordinate(52.386816, 16.974785)); // rynek
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}